import allure
from appium.webdriver.common.appiumby import AppiumBy
from selenium.webdriver.support import expected_conditions


from tests.app.pages.wecom import Wecom

class CompleteInputPage(Wecom):
    __COMPLETE_NAME=(AppiumBy.XPATH,"//*[@resource-id='com.tencent.wework:id/hll']/child::*/child::*[3]")
    __COMPLETE_ENTERPRISE_MAIL=(AppiumBy.XPATH,"//*[@resource-id='com.tencent.wework:id/jo0']/child::*/child::*[2]")
    __COMPLETE_PHONE=(AppiumBy.ID,"com.tencent.wework:id/j6_")
    __COMPLETE_PRESERVATION=(AppiumBy.XPATH,"//*[@text='保存']")
    __RETURN_BUTTON=(AppiumBy.ID,"com.tencent.wework:id/mh0")

    def add_first_members(self,name,ep_email,phone):
        from tests.app.pages.address_book_page import AddressBookPage
        self.find_and_send(*self.__COMPLETE_NAME,text=f"{name}")
        self.find_and_send(*self.__COMPLETE_ENTERPRISE_MAIL,text=f"{ep_email}")
        self.find_and_send(*self.__COMPLETE_PHONE,text=f"{phone}")
        with allure.step("点击保存"):
            self.swip_find(by=AppiumBy.XPATH,value="//*[@text='保存']")
            self.find_and_click(*self.__COMPLETE_PRESERVATION)
        self.wait(method=expected_conditions.visibility_of_element_located((self.__RETURN_BUTTON)))
        with allure.step("点击返回"):
            self.find_and_click(*self.__RETURN_BUTTON)
        return AddressBookPage(self.driver)